package mobidever.godutch.activity.base;

import java.lang.reflect.Field;

import mobidever.godutch.activity.R;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.LayoutInflater;
import android.widget.Toast;

public class ActivityBase extends Activity {
	protected static final int SHOW_TIME = 3000;
	private ProgressDialog m_ProgressDialog;

	protected void ShowMsg(String pMsg) {
		Toast.makeText(this, pMsg, 1000).show();
	}

	protected void ShowMsg(int p_ResID) {
		Toast.makeText(this, p_ResID, SHOW_TIME).show();
	}

	protected void OpenActivity(Class pClass) {
		Intent _Intent = new Intent(this, pClass);
		startActivity(_Intent);
	}

	protected LayoutInflater GetLayoutInflater() {
		LayoutInflater _LayoutInflater = LayoutInflater.from(this);
		return _LayoutInflater;
	}

	public void setAlertDialogIsClose(DialogInterface pDialog, Boolean pIsClose) {
		try {
			Field _Field = pDialog.getClass().getSuperclass()
					.getDeclaredField("mShowing");
			_Field.setAccessible(true);
			_Field.set(pDialog, pIsClose);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	protected AlertDialog ShowAlertDialog(int pTitleResID, String pMessage,
			DialogInterface.OnClickListener pClickListener) {
		String _Title = getResources().getString(pTitleResID);
		return ShowAlertDialog(_Title, pMessage, pClickListener);
	}

	protected AlertDialog ShowAlertDialog(String pTitle, String pMessage,
			DialogInterface.OnClickListener pClickListener) {
		return new AlertDialog.Builder(this)//
				.setTitle(pTitle)//
				.setMessage(pMessage)//
				.setPositiveButton(R.string.ButtonTextYes, pClickListener)//
				.setNegativeButton(R.string.ButtonTextNo, null)//
				.show();
	}

	protected void ShowProgressDialog(int p_TitleResID, int p_MessageResID) {
		m_ProgressDialog = new ProgressDialog(this);
		m_ProgressDialog.setTitle(getString(p_TitleResID));
		m_ProgressDialog.setMessage(getString(p_MessageResID));
		m_ProgressDialog.show();
	}

	protected void DismissProgressDialog() {
		if (m_ProgressDialog != null) {
			m_ProgressDialog.dismiss();
		}
	}
}
